#ifndef CODEGENCONTEXT_H
#define CODEGENCONTEXT_H

#include <stack>
#include <fstream>
#include "CodeGenBlock.hpp"

namespace MathematicaTranslator
{
	class CodeGenContext
	{

	public:
		CodeGenContext(const std::string& fileName);
		~CodeGenContext();

		bool matrixIntAdd;
		bool matrixDoubleAdd;
		bool matrixIntMul;
		bool matrixDoubleMul;
		bool matrixMul;
		bool listIntAdd;
		bool listDoubleAdd;
		bool listIntMul;
		bool listDoubleMul;
		bool listDot;
		bool listBinOp; 

		/// Main output stream
		std::ofstream generated;
		/// Startup method
		void generateCode(MTBlock& root);

		/// Blocks in flow that are being processed
		std::stack<CodeGenBlock*> blocks;
		/// Local variables from currently processed block, first param is variable name, second is it's value
		std::map<std::string, std::string*>& locals() { return blocks.top()->locals; }
		/// Get the currently processing block
		MTBlock* currentBlock() { return blocks.top()->block; }

		/// Set new context
		void pushBlock(MTBlock* block) ;	
		/// Remove new context
		void popBlock();		
		/// Duplicate stream used to output translation
		std::ofstream *getStream();
	};
}
#endif
